package cn.sytton.taffe.log.entity;

import cn.sytton.taffe.framework.base.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;

/**
 * Api访问日志Entity
 *
 * @author skyrock
 */
@Schema(description = "Api请求日志")
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_api_log")
public class ApiLogEntity extends BaseEntity {

    @Schema(description = "日志ID")
    @TableId(type = IdType.ASSIGN_ID)
    private String logId;         //日志ID

    @Schema(description = "用户ID")
    @JsonIgnore
    private String userId;      //用户ID

    @Schema(description = "登录账号")
    private String loginName;   //登录账号

    @Schema(description = "用户编号")
    private String userCode;    //用户编号

    @Schema(description = "用户姓名")
    private String userName;    //用户姓名

    @Schema(description = "访问来源: pc, android, ios, weixin")
    private String accessSource; //访问来源: pc, android, ios, weixin

    @Schema(description = "api路径")
    private String url;          //api路径

    @Schema(description = "Request方法 GET,POST")
    private String requestMethod; //Request方法 GET,POST

    @Schema(description = "Controller方法")
    private String method;        //Controller方法

    @Schema(description = "方法名称")
    private String methodName;    //方法名称

    @Schema(description = "请求参数")
    private String params;        //请求参数

    @Schema(description = "是否成功")
    private Boolean success;      //是否成功

    @Schema(description = "响应数据")
    private String result;        //响应数据

    @Schema(description = "错误信息")
    private String errMsg;        //错误信息

    @Schema(description = "IP地址")
    private String ip;            //IP地址

    @Schema(description = "物理地址")
    private String location;      //物理地址

    @Schema(description = "访问操作系统")
    private String os;            //访问操作系统

    @Schema(description = "访问浏览器")
    private String browser;        //访问浏览器

    @Schema(description = "访问开始时间")
    @JsonFormat
    private Timestamp beginTime;  //访问开始时间

    @Schema(description = "访问结束时间")
    @JsonFormat
    private Timestamp endTime;    //访问结束时间

    //-----以下是关联属性-----

    @Schema(description = "查询开始时间")
    @JsonFormat
    @TableField(exist = false)
    private Timestamp queryBeginTime;  //查询开始时间

    @Schema(description = "查询结束时间")
    @JsonFormat
    @TableField(exist = false)
    private Timestamp queryEndTime;    //查询结束时间
}
